<template>
  <el-container>
    <div class="header">
      <div class="title">苏小课直播教学平台</div>
      <div class="user-info">
        <div class="notification">
          <i class="bell-icon">🔔</i>
          <span class="badge">1</span>
        </div>
        <div class="user">您好，{{ userStore.uname }}！</div>
        <div class="actions">
          <a href="./login.html">退出</a>
        </div>
      </div>
    </div>
    <el-header>
      <div class="breadcrumb-nav">
        <el-breadcrumb separator="/">
          <el-breadcrumb-item @click='navigateTo("teacherHome/home.html")'>首页</el-breadcrumb-item>
          <el-breadcrumb-item @click='navigateTo("myCourse/myCourse.html")'>我的课程</el-breadcrumb-item>
          <el-breadcrumb-item>添加课程</el-breadcrumb-item>
        </el-breadcrumb>
      </div>
    </el-header>

    <el-main>
      <div class="content-wrapper">
        <el-form :model="course" label-width="100px">
          <el-form-item label="课程名称">
            <el-input v-model="course.name" placeholder="请输入课程名称"></el-input>
          </el-form-item>
          <el-form-item label="授课老师">
            <el-input v-model="course.teacher" placeholder="请输入授课老师名称"></el-input>
          </el-form-item>
          <el-form-item label="开始日期">
            <el-date-picker
              v-model="course.startTime"
              type="date"
              placeholder="选择开始日期"
              style="width: 100%;"
              value-format="YYYY-MM-DD"
            ></el-date-picker>
          </el-form-item>
          <el-form-item label="结束日期">
            <el-date-picker
              v-model="course.endTime"
              type="date"
              placeholder="选择结束日期"
              style="width: 100%;"
              value-format="YYYY-MM-DD"
            ></el-date-picker>
          </el-form-item>
          <el-form-item label="课时">
            <el-input v-model="course.duration" placeholder="请输入课时数"></el-input>
          </el-form-item>
          <el-form-item label="课程描述">
            <el-input
              v-model="course.description"
              type="textarea"
              placeholder="请输入课程描述"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="submitCourse">提交</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-main>
  </el-container>
</template>

<script setup>
import { useUserStore } from "../../store/user.js";
let userStore = useUserStore();
userStore.storeInit();

import "../../../public/header.css";

import { ref } from "vue";
import axios from 'axios';

const course = ref({
  name: "",
  teacher: "",
  startTime: "",
  endTime: "",
  duration: 0,
  description: "",
});

const submitCourse = () => {
  console.log(course.value.startTime)
  axios({
    url: "http://localhost:9090/addCourse",
    method: "POST",
    data: {
      name: course.value.name,
      teacher: course.value.teacher,
      startTime: course.value.startTime,
      endTime: course.value.endTime,
      duration: course.value.duration,
      description: course.value.description,
    },
  })
    .then((response) => {
      console.log("课程提交成功", response);
      // 可在此添加成功后提示
      location.reload();
    })
    .catch((error) => {
      console.log("课程提交失败", error);
      // 可在此添加失败后提示
    });
};

function navigateTo(page) {
  window.location.href = `/src/pages/${page}`;
}
</script>

<style scoped>
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  background-color: #fff;
  border-bottom: 1px solid #ddd;
}

.header .title {
  font-size: 24px;
  color: #1e90ff;
}

.header .user-info {
  display: flex;
  align-items: center;
}

.header .user-info .notification {
  margin-right: 20px;
  position: relative;
}

.header .user-info .notification .badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background-color: red;
  color: #fff;
  border-radius: 50%;
  padding: 2px 5px;
  font-size: 12px;
}

.header .user-info .user {
  margin-right: 10px;
  color: #333;
}

.header .user-info .actions a {
  margin: 0 5px;
  color: #1e90ff;
  text-decoration: none;
}

.el-header {
  background-color: #fff;
  padding: 10px;
  border-bottom: 1px solid #ddd;
}

.breadcrumb-nav {
  padding: 0 20px;
}

.content-wrapper {
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  padding: 20px;
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

.el-form-item {
  margin-bottom: 20px;
}
</style>
